// Learn cc.Class:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://docs.cocos2d-x.org/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] https://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] https://www.cocos2d-x.org/docs/creator/manual/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        Light:[cc.Node],
        // eslint-disable-next-line camelcase
        m_fire:cc.Node,
        gun:cc.Node,
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {

    },
    onLoad(){
        // console.log('飞机光圈动画');
        /*cc.repeatForever var repeat = cc.repeatForever(cc.rotateBy(1.0, 360)); this.node.runAction(repeat) ,repeat
        这个动作不能放到sequence,循环的执行一个动作序列，就把这个动作序列扔到cc.repeatForever，当一个动作执行完后，我们要干某些事情，就把cc.callFunc()*/

        let seq0 = cc.sequence(cc.delayTime(0),cc.scaleTo(0.4,1,1),cc.callFunc(function(){
            this.Light[0].setScale(0);


        },this),cc.delayTime(0.5)) ;
        let seq1 = cc.sequence(cc.delayTime(0.2),cc.scaleTo(0.4,1,1),cc.callFunc(function(){this.Light[1].setScale(0);},this),cc.delayTime(0.5)) ;
        let seq2 = cc.sequence(cc.delayTime(0.4),cc.scaleTo(0.4,1,1),cc.callFunc(function(){this.Light[2].setScale(0);},this),cc.delayTime(0.5)) ;
        this.Light[0].runAction(cc.repeatForever(seq0));
        this.Light[1].runAction(cc.repeatForever(seq1));
        this.Light[2].runAction(cc.repeatForever(seq2));


    },
    play(){
        this.node.setScale(0.8,0.8);
        this.m_fire.setScale(1,1);
        let seq = cc.spawn(cc.moveTo(0.5,cc.v2(0,-406)),cc.scaleTo(0.5,1,1));
        this.node.runAction(seq);
        //移入的时候，飞机放大，尾焰缩小
        this.m_fire.runAction(cc.scaleTo(0.5,0.6,0.6));

    },
    moveIn(){
        this.node.stopAllActions();
        this.node.runAction(cc.scaleTo(0.5,1,1));
        this.m_fire.runAction(cc.scaleTo(0.5,0.6,0.6));
    },
    moveOut(){
        this.m_fire.runAction(cc.scaleTo(0.5,0.8,0.8));
        this.m_fire.runAction(cc.scaleTo(0.5,1,1));
    },
    startFire(){
        this.gun.getComponent('gun').setBulletcount(6);
        this.gun.getComponent('gun').startFire();
    },
    endFire(){
        this.gun.getComponent('gun').endFire();
    },

    // update (dt) {},
});
